<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>健康食谱</title>
      <link rel="stylesheet" type="text/css" href="../xhAdmin/css/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../xhAdmin/css/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../xhAdmin/css/themes/color.css">
    <link rel="stylesheet" type="text/css" href="../xhAdmin/css/demo/demo.css">
    <script type="text/javascript" src="../xhAdmin/js/jquery.min.js"></script>
    <script type="text/javascript" src="../xhAdmin/js/jquery.easyui.min.js"></script>
</head>

<body>
    <div id="toolbar-link">
        <a href="javascript:void(0)" id="linkAddBtn" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="linkAdd()">添加</a>
        <a href="javascript:void(0)" id="linkEditBtn" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="linkEdit()">修改</a>
        <a href="javascript:void(0)" id="linkDestroyBtn" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="linkDestroy()">删除</a>
    </div>
    <table id="link-table" class="easyui-datagrid" data-options="fit:true,border:false,url:'../xhLink/all',method:'get'" style="width:auto;height:100%" toolbar="#toolbar-link" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true" pageSize="20">
        <thead>
            <tr>
              	<th field="style" width="25%" align="center">链接类别分类</th>
              	<th field="link" width="25%" align="center">链接</th>
                <th field="user" width="25%" align="center">分享人</th>
                <th field="description" width="25%" align="center">描述</th>
            </tr>
        </thead>
    </table>
    <div id="dlg-linkAdd" class="easyui-dialog" style="width:650px;height:393px;padding:1px 1px" closed="true" buttons="#dlg-linkAdd-btn" align="center" data-options="modal:true">
        <form id="fm-linkAdd" method="post" novalidate>
            <table class="pattern" border="0">
              <tr>
				<th width="18%">链接类别分类：</th>
				<td width="32%"><input type="text" id="style" name="style" class="easyui-textbox" style="width:100%"></td>
				<th width="18%">链接：</th>
				<td width="32%"><input type="text" id="link" name="link" class="easyui-textbox" style="width:100%"></td>
			</tr>
			<tr>
				<th width="18%">分享人：</th>
				<td width="32%"><input type="text" id="user" name="user" class="easyui-textbox" style="width:100%"></td>
			</tr>
			
			<tr>
                    <th>描述：</th>
                    <td colspan="3">
                        <input class="easyui-textbox" id="description" name="description" style="width:100%;height:80px" data-options="multiline:true" style="width:100%" />
                    </td>
                </tr>
			 
            </table>
        </form>
    </div>
    <div id="dlg-linkAdd-btn">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="linkAddSave()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg-linkAdd').dialog('close')" style="width:90px">关闭</a>
    </div>
    <div id="dlg-linkEdit" class="easyui-dialog" style="width:650px;height:393px;padding:1px 1px" closed="true" buttons="#dlg-linkEdit-btn" align="center" data-options="modal:true">
        <form id="fm-linkEdit" method="post" novalidate>
            <table class="pattern" border="0">
			    <tr>
				<th width="18%">链接类别分类：</th>
				<td width="32%"><input type="text" id="style" name="style" class="easyui-textbox" style="width:100%"></td>
				<th width="18%">链接：</th>
				<td width="32%"><input type="text" id="link" name="link" class="easyui-textbox" style="width:100%"></td>
			</tr>
			<tr>
				<th width="18%">分享人：</th>
				<td width="32%"><input type="text" id="user" name="user" class="easyui-textbox" style="width:100%"></td>
			</tr>
			
			<tr>
                    <th>描述：</th>
                    <td colspan="3">
                        <input class="easyui-textbox" id="description" name="description" style="width:100%;height:80px" data-options="multiline:true" style="width:100%" />
                    </td>
                </tr>
            <input type="hidden" name="id" />
            <input type="hidden" name="timestamp" />
			</table>
        </form>
    </div>
    <div id="dlg-linkEdit-btn">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="linkEditSave()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg-linkEdit').dialog('close')" style="width:90px">关闭</a>
    </div>
    <div id="dlg-linkReadonly" class="easyui-dialog" style="width:650px;height:393px;padding:1px 1px" closed="true" buttons="#dlg-linkReadonly-btn" align="center" data-options="modal:true">
        <form id="fm-linkReadonly" method="post" novalidate>
            <table class="pattern" border="0">
			    <tr>
				<th width="18%">链接类别分类：</th>
				<td width="32%"><input type="text" id="style" name="style" class="easyui-textbox" style="width:100%"></td>
				<th width="18%">链接：</th>
				<td width="32%"><input type="text" id="link" name="link" class="easyui-textbox" style="width:100%"></td>
			</tr>
			<tr>
				<th width="18%">分享人：</th>
				<td width="32%"><input type="text" id="user" name="user" class="easyui-textbox" style="width:100%"></td>
			</tr>
			
			<tr>
                    <th>描述：</th>
                    <td colspan="3">
                        <input class="easyui-textbox" id="description" name="description" style="width:100%;height:80px" data-options="multiline:true" style="width:100%" />
                    </td>
                </tr>
			 
            <input type="hidden" name="id" />
            <input type="hidden" name="timestamp" />
			</table>
        </form>
    </div>
    <div id="dlg-linkReadonly-btn">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg-linkReadonly').dialog('close')" style="width:90px">关闭</a>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        /*$.post('/jg/checkScope', {
            sessionName: 'f9'
        }, function(data) {
            if (data == false) {
                $('#toolbar-link #linkAddBtn').hide();
                $('#toolbar-link #linkEditBtn').hide();
                $('#toolbar-link #linkDestroyBtn').hide();
            }
        }, 'json');*/

        $("#link-table").datagrid({
            //双击事件  
            onDblClickRow: function(index, row) {
                if (row) {
                    $('#dlg-linkReadonly').dialog('open').dialog('center').dialog('setTitle', '查看常用链接信息');
                    $('#fm-linkReadonly').form('load', row);
                }
            }
        });

    });

    function linkAdd() {
        $('#dlg-linkAdd').dialog('open').dialog('center').dialog('setTitle', '添加常用链接');
        $('#fm-linkAdd').form('clear');
    }

    function linkAddSave() {
        $('#fm-linkAdd').form('submit', {
            url: '../xhLink/add',
            onSubmit: function() {
                //进行表单验证
                //如果返回false阻止提交
                return $(this).form('enableValidation').form('validate');
            },
            success: function(data) {
                var data = eval('(' + data + ')'); // change the JSON string to javascript object
                if (data.result == 'success') {
                    $('#dlg-linkAdd').dialog('close');
                    $('#link-table').datagrid('reload');
                    $.messager.show({ // show error message
                        title: '操作完成',
                        msg: data.description
                    });
                } else {
                    $.messager.show({ // show error message
                        title: '出错了',
                        msg: data.description
                    });
                }
            }
        });

    }

    function linkEdit() {
        var row = $('#link-table').datagrid('getSelected');
        if (row) {
            $('#dlg-linkEdit').dialog('open').dialog('center').dialog('setTitle', '修改常用链接');
            $('#fm-linkEdit').form('load', row);
        }
    }

    function linkEditSave() {
        $('#fm-linkEdit').form('submit', {
            url: '../xhLink/update',
            onSubmit: function() {
                //进行表单验证
                //如果返回false阻止提交
                return $(this).form('enableValidation').form('validate');
            },
            success: function(data) {
                var data = eval('(' + data + ')'); // change the JSON string to javascript object
                if (data.result == 'success') {
                    $('#dlg-linkEdit').dialog('close');
                    $('#link-table').datagrid('reload');
                    $.messager.show({ // show error message
                        title: '操作完成',
                        msg: data.description
                    });
                } else {
                    $.messager.show({ // show error message
                        title: '出错了',
                        msg: data.description
                    });
                }
            }
        });
    }

    function linkDestroy() {
        var row = $('#link-table').datagrid('getSelected');
        if (row) {
            $.messager.confirm('删除', '是否彻底删除该常用链接？？？', function(r) {
                if (r) {
                    $.post('../xhLink/delete', {
                        id: row.id
                    }, function(data) {
                        if (data.result == 'success') {
                            $('#link-table').datagrid('reload'); // reload the user data
                            $.messager.show({ // show error message
                                title: '操作完成',
                                msg: data.description
                            });
                        } else {
                            $.messager.show({ // show error message
                                title: '出错了',
                                msg: data.description
                            });
                        }
                    }, 'json');
                }
            });
        }
    }
    </script>
</body>

</html>
